class Solution {
public:
    vector<int> resultsArray(vector<int>& nums, int k)
    {
        if (k == 1) return nums;
        vector<int> ans;
        int n = nums.size();
        for (int i = 0; i < n - k + 1; i++)
        {
            int mx = -1;
            for (int j = i, m = i + 1; j < i + k - 1; j++, m++)
            {
                if (nums[m] != nums[j] + 1)
                {
                    mx = -1;
                    break;
                }
                else mx = nums[m];
            }
            ans.push_back(mx);
        }

        return ans;
    }
};